<?php
namespace Home\Controller;
use Think\Controller;

class SearchController extends Controller{

	// 搜索主页   处理搜索
	public function index(){


		// 显示家乡
		$love_district =  D("district");
		//省 的结合
		$data = $love_district ->where('upid = 0')->select();


		// 接收搜索信息
		dump(I());
		// 年龄 小
		$age = I('post.age');
		$age1 = I('post.age1');

		dump(I('post.age'));
		dump(I('post.age1'));
		// 性别
		dump(I('post.sex'));
		$sex = I('post.sex');
		// 婚史  0 未婚 1 离异 2 丧偶
		dump(I('post.status'));
		$status = I('post.status');
		// 有无子女  0没有子女 1有子女
		$child = I('post.child');
		dump(I("post.child"));
		// 家乡 
		dump(I("post.home"));
		$home = I('post.home');
		//身高 多少到多少
		$height = I('post.height');
		$height1 = I('post.height1');
		dump(I('post.height'));
		dump(I('post.height1'));
		// 学历 1 初中 2 中专/职高/技校 3 高中 4 大专 5 本科 6 硕士 7 博士 8 博士后
		$edu = I('post.edu');
		dump(I('post.edu'));
		//住房 0 以后告诉你 1 没有房子 2 有房子（还贷中）3 有房子（无贷款）
		$house = I('post.house');
		dump(I('post.house'));
		// 月收入 1 2000以下 2 2000-4000 3 4000-6000 4 6000-8000 5 8000-10000 6 10000以上
		$money = i('post.money');
		dump(I('post.money'));
		// 职务 0下岗   1国企  2民企  3个体商户  4其他   --
		$business = I('post.business');
		dump(I('post.business'));
	
		// 给所有的条件加初始值
		if($age == ''){
			$age = '18';
		}else{
			$age;
		}
		if($age1 == ''){
			$age1 = '25';
		}else{
			$age1 = $age1;
		}
		if($height == ''){
			$height = '145';
		}else{
			$height = $height;
		}
		if($height1 == ''){
			$height1 = '200';
		}else{
			$height1 = $height1;
		}

	////////  搜索姓名
		$name = I('post.name');	
	// dump(I('post.name'));	
		



		// 链接数据库
		$userinfo = D("userinfo");
		$love = array();
		$love['age'] = array(array('EGT',$age,),array("ELT",$age1),'and');
		// 判断性别

		$love['sex'] = array('EQ',$sex);
		
		if($status != ''){
			$love['status'] = array('EQ',$status);
		}
		

		$love['child']  = array("EQ",$child);
		// 家乡
		//$love['home'] = array("EQ",$home);

		$love['height'] = array(array('EGT',$height,),array("ELT",$height1),'and');
		if($edu  != ''){
			$love['edu']  = array("EQ",$edu);
		}
		
		$love['house'] = array('EQ',$house);
		if($money != ''){
			$love['money'] = array('EQ',$money);
		}
	   
	   if($business != ''){
	   	 $love['business'] = array('EQ',$business);
	   }
	   
		

		//$love['_logic'] = "and";
	    if($name != ''){
	    	$list = $userinfo->where("name = '{$name}'")->select();
	    }else{
	    	$list = $userinfo->where($love)->select();
	    }

	    	
		

		dump($list);

		//把身高 和年龄放到数组里面去

		$ageheight = array();
		$ageheight['age'] = $age;
		$ageheight['age1'] = $age1;
		$ageheight['height'] = $height;
		$ageheight['height1'] = $height1;
		


		// 省遍历出去
		$this->assign('ageheight',$ageheight);
		$this->assign('dataList1',$list);
		$this->assign("birthday_year",$data);
		$this->display();
	}

	//处理json数据
	public function deal(){
		$id = I('get.id/d',0);
	/*	var_dump($id);*/
		$district = M('love_district')->where("upid=$id")->select();
		
		// $dthis->assign('dis',$district);
		$this->ajaxReturn($district);
	}



}